import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
};
type ResultDelete = {
  code: number;
  message: string;
};
type ResultCreate = {
  code: number;
  message: string;
};
type Show = {
  code: number;
  message: string;
  result?: any;
};

/** 零件列表 */
export const partListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/product/part/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件添加 */
export const partStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/product/part/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件编辑 */
export const partUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/product/part/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};


/** 零件详情 */
export const partShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/product/part/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件删除 */
export const partDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/product/part/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件选择 */
export const partSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/product/part/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};


/** 供应商列表 */
export const supplierListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/supplier/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 供应商添加 */
export const supplierStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/supplier/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 供应商编辑 */
export const supplierUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/supplier/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};


/** 供应商详情 */
export const supplierShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/supplier/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 供应商删除 */
export const supplierDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/supplier/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 供应商选择 */
export const supplierSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/supplier/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/**
 * *
 * 公司API
 *
 * /
 *
 */
/** 公司列表 */
export const companyListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/company/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 公司添加 */
export const companyStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/company/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 公司编辑 */
export const companyUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/company/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};


/** 公司详情 */
export const companyShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/company/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 公司删除 */
export const companyDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/company/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 公司选择 */
export const companySelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/company/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/**
 * *
*品牌API
*
*
*/
/** 品牌列表 */
export const brandListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/brand/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 品牌添加 */
export const brandStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/brand/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 品牌编辑 */
export const brandUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/brand/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};


/** 品牌详情 */
export const brandShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/brand/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 品牌删除 */
export const brandDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/brand/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 品牌选择 */
export const brandSelectApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/brand/select", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/**
 * *
*零件分类API
*
*
*/
/** 零件分类列表 */
export const categoryListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/category/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件分类添加 */
export const categoryStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/category/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件分类编辑 */
export const categoryUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/category/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 分类状态更新 */
export const categoryUpdateStatusApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/category/updateStatus", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件分类详情 */
export const categoryShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/category/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件分类删除 */
export const categoryDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/category/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 零件分类选择 */
export const categorySelectApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/category/select", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/**
 * *
*设备API
*
*
*/
/** 设备列表 */
export const productListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/product/device/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 设备添加 */
export const productStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/product/device/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 设备编辑 */
export const productUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/product/device/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};


/** 设备详情 */
export const productShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/product/device/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 设备删除 */
export const productDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/product/device/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 设备选择 */
export const productSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/product/device/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
